/*
*         Copyright (c), NXP Semiconductors Bangalore / India
*
*                     (C)NXP Semiconductors
*       All rights are reserved. Reproduction in whole or in part is
*      prohibited without the written consent of the copyright owner.
*  NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
* particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
*                          arising from its use.
*/

#ifndef PHALMFDFEVX_SAM_X_INT_H
#define PHALMFDFEVX_SAM_X_INT_H

#include <phalMfdfEVx.h>

#define PHAL_MFDFEVX_MAX_WRITE_LEN		60		/* The default frame size is 64 bytes. So if the Write related commands need to transmitted to the PICC via SAM,
												 * the command including the data to be written and excluding PICC header comes to 60 bytes.
												 */

/* Sam maximum single frame size. */
#define PHAL_MFDFEVX_SAM_DATA_FRAME_LENGTH					224		/* Maximum data that can be exchanged in case of secure messaging computation by SAM. */

#define PHAL_MFDFEVX_SAM_X_SESSION_TMAC_ENC					0x01	/**< Option to perform generate the TMAC session encryption keys. */
#define PHAL_MFDFEVX_SAM_X_SESSION_TMAC_MAC					0x02	/**< Option to perform generate the TMAC session MAC keys. */
#define PHAL_MFDFEVX_SAM_X_SESSION_ENC						0x01	/**< Optionto perform generate the SDM session encryption keys. */
#define PHAL_MFDFEVX_SAM_X_SESSION_MAC						0x02	/**< Optionto perform generate the SDM session MAC keys. */

/* Resolves the component to be used. */
#define PHAL_MFDFEVX_RESOLVE_DATAPARAMS(DataParams)	((phalMfdfEVx_SamAV3_X_DataParams_t *) DataParams)

/* Resolves the Hal component to be used for communicating with Sam hardware in X mode. */
#define PHAL_MFDFEVX_RESOLVE_HAL_DATAPARAMS(DataParams)																							\
			(PH_GET_COMPID(DataParams) == PHAL_MFDFEVX_SAMAV3_X_ID) ? ((phalMfdfEVx_SamAV3_X_DataParams_t *) DataParams)->pHalSamDataParams :	\
			NULL

phStatus_t phalMfdfEVx_Sam_X_Int_ValidateResponse(void * pDataParams, uint16_t wStatus, uint8_t * pPiccRetCode);

phStatus_t phalMfdfEVx_Sam_X_Int_Iso7816Wrap(void * pDataParams, uint8_t bFirstFrame, uint8_t bLengthPresent, uint8_t bLengthLen, uint8_t bLePresent,
	uint32_t dwTotDataLen, uint8_t * pPlainData, uint16_t * pDataLen);

phStatus_t phalMfdfEVx_Sam_X_Int_GetKeyInfo(void * pDataParams, uint8_t bKeyNo, uint16_t * pKeyType, uint16_t * pSET, uint16_t * pExtSET);

phStatus_t phalMfdfEVx_Sam_X_Int_ComputeTMACSessionVectors(void * pDataParams, uint8_t bOption, uint16_t wSrcKeyNo, uint16_t wSrcKeyVer, uint16_t wDstKeyNo, 
	uint8_t * pTMC, uint8_t * pUid, uint8_t bUidLen);

phStatus_t phalMfdfEVx_Sam_X_Int_ComputeSDMSessionVectors(void * pDataParams, uint8_t bOption, uint8_t bSdmOption, uint16_t wSrcKeyNo, uint16_t wSrcKeyVer, 
	uint16_t wDstKeyNo, uint8_t * pUid, uint8_t bUidLen, uint8_t * pSDMReadCtr);

phStatus_t phalMfdfEVx_Sam_X_Int_LoadSDMInitVector(void * pDataParams, uint8_t * pSDMReadCtr);

#endif /* PHALMFDFEVX_SAM_X_INT_H */
